package interfaces.kernel;

import java.io.File;
import java.util.Map;

/**
 * ORB is the main component of Java Ca&La. It locates the object,
 * solving location and name transparencies, and calls a stub 
 * to proceed the rpc. Communication Fault tolerance are implemented in orbs.
 * @author Joubert Lima
 * @version 2.0
 */
public interface JCL_orb <R extends JCL_result>{
	
	

	/**
	 * @param mainComponentClass the class to be executed remotely
	 * @param nickName the class name to be used by JCL
	 * @return true if it has successfully registered, false otherwise
	 */
	public abstract boolean register (Class<?> mainComponentClass, String nickName);
	
	/**
	 * @param jars the jar file (first file) and its dependencies
	 * (the remaining files) registered
	 * @param classToBeExecuted the class name to be used by JCL. No class packages. 
	 * @return true if it has successfully registered, false otherwise
	 */
	public boolean register(File[] jars, String classToBeExecuted);
	
		
	/**
	 * @param task - the task to be executed
	 * 
	 */
	public abstract void execute (JCL_task task, Map<String, R> results);
	
	/**
	 * @param nickName - the variable nickname
	 * @param className - the class to be executed to instantiate the global var
	 * @param defaultVarValue - the constructor variable arguments
	 * @return - return the instance if the variable is created. null otherwise.
	 */
	public abstract Object instantiateGlobalVar(String nickName, String className, File[] jars, Object[] defaultVarValue);

	/**
	 * @param varName - the variable name
	 * @param instance - a user variable value
	 * @return - return true if the variable is registered. False otherwise.
	 */
	public abstract boolean instantiateGlobalVar(String varName, Object instance);

	/**
	 * @param varName - the variable name
	 * @return - return true if the variable is set null. False otherwise.
	 * if the variable is previously locked the destroy will return false.
	 * the user must unlock first and destroy after.
	 */
	public abstract boolean destroyGlobalVar(String varName);

	
	/**
	 * Updates the variable value. The setValue is not performed if a variable is previously locked.  
	 * 
	 * @param varName - global variable name
	 * @param value - global variable value
	 * @return true if value is correctly updated or false otherwise
	 */
	public abstract boolean setValue (String varName, Object value);
	
	/**
	 * Updates the variable value. Unlock a variable if it is previously locked.  
	 * 
	 * @param varName - global variable name
	 * @param value - global variable value
	 * @return true if value is correctly updated or false otherwise
	 */
	public abstract boolean setValueUnlocking (String varName, Object value);
	
	
	/**
	 * @param varName - global variable name
	 * @return the global variable value or an error or null if no variable exists
	 */
	public abstract JCL_result getValue(String varName);
	
	
	/**
	 * @param varName - global variable name
	 * @return the global variable value or an error or null if no variable exists. 
	 * 
	 * the pair getValueLocking and setValueUnlocking implements critical sections in Java Ca&La
	 */
	public abstract JCL_result getValueLocking(String varName);


	/**
	 * @param nickName the class name to be removed by JCL
	 * @return true if it is removed, false otherwise
	 */
	public abstract boolean unRegister (String nickName);
	
	/**
	 * verify if there is a task registered in JCL
	 * 
	 * @param nickName the task name
	 * @return true if JCL contains such a task, false otherwise
	 */
	public abstract boolean containsTask(String nickName);
	
	/**
	 * verify if there is a global variable registered in JCL
	 * 
	 * @param nickName the global var name
	 * @return true if JCL contains such a global variable, false otherwise
	 */
	public abstract boolean containsGlobalVar(String nickName);


}
